package com.xzzz.irda.guardcat.server.app.pojo;

import com.xzzz.common.base.enums.BackendServiceEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Objects;

/**
 * @author xzzz
 */
@Data
@Accessors(chain = true)
public class AppRelationVO {

    private String source;
    private String target;

    private String value;

    private String type;
    private Integer num;


    public String getSortName() {
        int source = BackendServiceEnum.getByName(this.source).getSort();
        int target = BackendServiceEnum.getByName(this.target).getSort();
        if (source < target) {
            return this.source + ">" + this.target;
        } else {
            return this.target + ">" + this.source;
        }
    }


    @Override
    public int hashCode() {
        return Objects.hash(source, target, type);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (!(o instanceof AppRelationVO)) {
            return false;
        }

        AppRelationVO that = (AppRelationVO) o;

        return Objects.equals(source, that.source) &&
                Objects.equals(target, that.target) &&
                Objects.equals(type, that.type)
                ;
    }

}
